package com.jz.util;
/*
 * @(#)ObjectFormatUtils.java 2010-3-8
 * 
 * Copyright 5jxiang . All rights reserved.
 
package com.www.util;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import flex.messaging.io.amf.ASObject;

*//**
 * <p>
 * <a href="ObjectFormatUtils.java.html"><i>View Source</i></a>
 * </p>
 *
 * @author 5jxiang
 * @version $Id$
 *//*
public class ObjectFormatUtils {
	public static ASObject JsonToAs(JSONObject js) throws JSONException{
		if (js == null) return null;
		ASObject asObject = new ASObject();
		Iterator<String> keys = js.keys();
		while (keys.hasNext()) {
			String key = keys.next();
			Object value = js.get(key);
			if (value instanceof JSONObject) {
				value = JsonToAs((JSONObject)value);
			} else if (value instanceof JSONArray) {
				value = JsonArrayToASArray((JSONArray)value);
			}
			asObject.put(key, value);
		}
		return asObject;
	}
	
	public static Object[] JsonArrayToASArray(JSONArray jsa) throws JSONException{
		if (jsa == null) return null;
		List<Object> objects = new ArrayList();
		for(int i = 0; i < jsa.length(); i++) {
			Object obj = jsa.get(i);
			if (obj instanceof JSONObject) {
				objects.add(JsonToAs((JSONObject)obj));
			} else {
				objects.add(obj);
			}
		}
		return objects.toArray(new ASObject[objects.size()]);
			
	}
	
	public static JSONArray arrayToJsonArray(Object[] array) throws JSONException{
		if (array == null) return null;
		JSONArray ja = new JSONArray();
		for(Object obj : array) {
			if (obj instanceof Map) {
				ja.put(mapToJson((Map)obj));
			} else {
				ja.put(obj);
			}
		}
		return ja;
			
	}
	
	public static JSONObject mapToJson(Map as) throws JSONException{
		if (as == null) return null;
		JSONObject jo = new JSONObject();
		Iterator iter = as.keySet().iterator();
		while (iter.hasNext()) {
			Object key = iter.next();
			Object value = as.get(key);
			if (value instanceof Array) {
				value = arrayToJsonArray((Object[])value);
			} else if (value instanceof Map) {
				value = mapToJson((Map)value);
			}
			jo.put(String.valueOf(key), value);
		}
		return jo;
		
	}
	
	
}
*/